package com.tianzeculture.stagebao.activity.personal;

import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.base.BaseActivity;
import com.tianzeculture.stagebao.net.UserRestUsage;
import com.tianzeculture.stagebao.network.Request;
import com.tianzeculture.stagebao.network.enity.MSG;
import com.tianzeculture.stagebao.network.util.ToastUtil;
import com.tianzeculture.stagebao.util.StatusBarUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/6/22 0022.
 * 修改密码
 */

public class ModifyPwdActivity extends BaseActivity {
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.edtOldPwd)
    EditText edtOldPwd;
    @BindView(R.id.edtNewPwd)
    EditText edtNewPwd;
    @BindView(R.id.edtNewPwdAgain)
    EditText edtNewPwdAgain;
    @BindView(R.id.btnSure)
    Button btnSure;

    @Request
    UserRestUsage userRestUsage = null;
    private int updatePassword = 101;

    @Override
    public void initUI() {
        super.initUI();
        tvTitle.setText("修改密码");
        StatusBarUtil.setWindowStatusBarColor(this, R.color.colorGray_F8);
    }

    @OnClick(R.id.btnSure)
    public void updatePwd() {
        if ("".equals(edtOldPwd.getText().toString().trim())) {
            ToastUtil.showShort(this, "当前密码不能为空!");
            return;
        } else if ("".equals(edtNewPwd.getText().toString().trim())) {
            ToastUtil.showShort(this, "新密码不能为空!");
            return;
        } else if (!(edtNewPwd.getText().toString().trim()).equals(edtNewPwdAgain.getText().toString().trim())) {
            ToastUtil.showShort(this, "两次密码不一致!");
            return;
        }

        userRestUsage.updatePassword(updatePassword, edtOldPwd.getText().toString().trim(),
                edtNewPwd.getText().toString().trim());
    }

    @Override
    public void refreshUI(int taskId, MSG msg) {
        super.refreshUI(taskId, msg);
        if (taskId == updatePassword) {
            if (msg.getData())
                finish();
        }
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_modify_pwd;
    }

}
